const angular = require('angular');
require('angular-sanitize')
require('jquery');
require('angular-route');
require('../contract/contract-ctrl');
require('../invoice/list');
require('../balance/list');
require('../abnormal/violated-contract-list');
require('../abnormal/special-invoice-list');
require('../abnormal/special-authorize-list');
require('../tenant/tenant');
require('../tenant/ctrl-authorize');
require('../tenant/ctrl-image');
require('../refund/index');
require('../expcenter/index');
require('../../../../picture_manager/js/picture_manager');
require('../../../../budget/js/budget');
require('../../../../process_center/js/process_center');
require('../side');

const app = angular.module('myBackendApp', [
    'ngRoute', 'Contract', 'Invoice', 'Balance', 'ViolatedContract',
    'SpecialInvoice', 'SpecialAuthorize', 'Tenant', 'Refund', 'ExpCenter',
    'ctrlTenantAuthorize', 'ctrlTenantImage', 'PictureManager', 'Budget', 'ProcessCenter',
    'ngSanitize'
]);

app
    .config(($routeProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) => {
            app.register = {
                controller: $controllerProvider.register,
                directive: $compileProvider.directive,
                filter: $filterProvider.register,
                factory: $provide.factory,
                service: $provide.service
            };
        }
    )
    .factory('config', function () {
        return {
            app: {
                name: '明源云客管理后台',
                description: '明源云客'
            },
            user: {
                name: '管理员',
                picture: ''
            }
        };
    })
    .config(['$routeProvider',
        function ($routeProvider) {
            $routeProvider
                .when("/", { redirectTo: '/contract' })
                .when('/contract', {
                    templateUrl: require('../../../../contract/list.html?url')
                })
                .when('/balance', {
                    templateUrl: require('../../../../balance/list.html?url')
                    //controller: 'balanceListCtrl'
                })
                .when('/invoice', {
                    templateUrl: require('../../../../invoice/list.html?url')
                    //controller: 'invoiceListCtrl'
                })
                .when('/violated_contract', {
                    templateUrl: require('../../../../abnormal/violated_contract_list.html?url'),
                    controller: 'violatedContractListCtrl'
                })
                .when('/special_approval_invoice', {
                    templateUrl: require('../../../../abnormal/special_invoice_list.html?url'),
                    controller: 'specialInvoiceListCtrl'
                })
                .when('/special_approval_authorize', {
                    templateUrl: require('../../../../abnormal/special_authorize_list.html?url'),
                    controller: 'specialAuthorizeListCtrl'
                })
                .when('/tenant', {
                    templateUrl: require('../../../../tenant/list.html?url'),
                    controller: 'tenantCtl'
                })
                .when('/tenant_authorize', {
                    templateUrl: require('../../../../tenant/authorize.html?url'),
                    controller: 'tenantAuthorizeCtl'
                })
                .when('/tenant_image', {
                    templateUrl: require('../../../../tenant/image.html?url'),
                    controller: 'tenantImageCtl'
                })
                .when('/refund', {
                    templateUrl: require('../../../../refund/index.html?url'),
                    controller: 'refundCtl'
                })
                .when('/menu_picture_manager', {
                    templateUrl: require('../../../../picture_manager/picture_manager.html?url'),
                    controller: 'pictureManagerCtl'
                })
                .when('/budget', {
                    templateUrl: require('../../../../budget/budget.html?url'),
                    controller: 'budgetCtl'
                })
                .when('/expcenter', {
                    templateUrl: require('../../../../expcenter/expcenter.html?url')
                })
                .when('/process_center', {
                    templateUrl: require('../../../../process_center/process_center.html?url')
                })
                .when('/revenue/:type', {
                    template: require('../../../../revenue/index.html'),
                    resolve: {
                        load: () => import('../../../../revenue/index')
                    }
                })
        }])
    .service('appservice', function ($rootScope) {
        return { name: '明源云客' };
    })
    .controller('appctrl', ['$scope', 'appservice', '$rootScope',
        function ($scope, appservice, $rootScope) {
            $scope.app = appservice;
        }])
angular.bootstrap(document, ['myBackendApp']);
